import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/login/login.vue'
import FirstPage from '../components/firstpage.vue';


import changepw from './changepw'
import owener from './owner';
import manage from './manage'
import worker from './worker'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },{
    path:'/page',
    component:FirstPage
  },
  {
    path: '/login',
    component: Login
  },
  //业主路由
  ...owener.routes
  ,
  //修改密码的路由
  ...changepw.routes,
  //管理员路由
  ...manage.routes,
  //工人
  ...worker.routes
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


export default router


// 路由守卫，类似于拦截器。
// router.beforeEach((to, from, next) => {
//   if (to.matched.some(record => record.meta.requiresAuth)) {
//     if (!sessionStorage.getItem("token")) {
//       console.log(sessionStorage.getItem("token"))
//       next({
//         path: '/login',
//         query: { redirect: to.fullPath }
//       })
//     } else {
//       next()
//     }
//   } else {
//     next() // 确保一定要调用 next()
//   }
// })




